package com.le.buddha.controller;

import cn.hutool.core.date.StopWatch;
import com.le.buddha.common.Response;
import com.le.buddha.conf.ThreadPoolConfig;
import com.le.buddha.mobile.VoiceModel;
import com.le.buddha.mobile.enums.SysConfigEnum;
import com.le.buddha.service.IFileService;
import com.le.buddha.service.ISysConfigService;
import com.le.buddha.service.IVoiceModeService;
import com.le.buddha.service.IVoiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author guole
 * @created 2025/5/25
 */
@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {
    @Resource
    private ThreadPoolConfig threadPoolConfig;
    @Resource
    private IVoiceService voiceService;
    @Resource
    private IFileService fileService;
    @Resource
    private ISysConfigService sysConfigService;
    @Resource
    private IVoiceModeService voiceModeService;

    @PostMapping("/voice")
    Response voice(@RequestParam("txt") String txt) {


        Long voiceId = Long.parseLong(sysConfigService.queryValueByCode(SysConfigEnum.声音模型ID.getCode()));
        VoiceModel voiceModel = voiceModeService.lambdaQuery().eq(VoiceModel::getId, voiceId).one();
        String modelName = voiceModel.getModelName();
        byte[] music = voiceService.textToSpeech(txt, modelName, null);
        String path = fileService.upload(music, "mp3", 2);

        return Response.success(path);
    }


}
